<template>
  <el-main>
    <el-form :model="formData" :rules="rules" ref="formData" label-width="100px" class="demo-ruleForm">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="formData.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="pwd">
        <el-input type="password" v-model="formData.pwd" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('formData')">登陆</el-button>
      </el-form-item>
    </el-form>
  </el-main>
</template>

<script>
export default {
  name: "Login",
  data() {
    return{
      formData:{},
      rules:{
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        pwd: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    submitForm(formData) {
      this.$refs[formData].validate((valid) => {
        if (valid) {
            this.axios.post(this.$baseUrl+"/hotel/login",this.formData).then(res=>{
              console.log("登陆信息",res);
              if (res.data.errCode == 500) {
                this.$message.error(res.data.message);
              } else {
                this.$message.success("登陆成功");
                localStorage.setItem("userinfo",JSON.stringify(res.data.data));
                this.$router.push("/hotel");
              }
            })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {

  }
}
</script>

<style scoped>

</style>